package com.episode.duetapi.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import com.episode.duetapi.model.Admin;
import com.episode.duetapi.utils.JwtHelper;

import io.jsonwebtoken.Claims;

public class JwtInterceptor implements HandlerInterceptor{
	
	private static final Logger logger = LoggerFactory.getLogger(JwtInterceptor.class);
	
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handle)throws Exception {
		String method = request.getMethod();
		if(method.equalsIgnoreCase("options")) {
			return true;
		}
		String token = request.getHeader("Authorization");
		Claims claims = JwtHelper.parseJWT(token);
		request.setAttribute("Authorization", claims);
		return true;
	}
}
